<?php

	class Customer{
		private $name;
		private $rentals;
		private $freque;

		public function __construct($name){
			$this->name = $name;
			$this->rentals = array();
		}

		public function addRental($rental){
			array_push($this->rentals,$rental);
		}

		public function statement(){
			echo "The statement of the Customer[{$this->name}]:<br />";
			$sum = 0;
			$sum_freque = 0;
			foreach($this->rentals as $item){
				$movie = $item->getMovie();
				echo "The Movie:",$movie->getTitle()," , daysRentaled costs:",$item->getRentalMoney(),"<br />";
				echo "The Movie:",$movie->getTitle()," , freque is:",$item->getRentalFreque(),"<br />";
				$sum+=$item->getRentalMoney();
				$sum_freque += $item->getRentalFreque();
			}
			echo "Total Cost:",$sum,"<br />";
			echo "Total Freque:",$sum_freque,"<br />";
		}

	}

	class Rental{

		private $movie;
		private $daysRentaled;

		public function __construct($movie,$daysRentaled){
			$this->movie = $movie;
			$this->daysRentaled = $daysRentaled;
		}

		public function getDaysRentaled(){
			return $this->daysRentaled;
		}

		public function getMovie(){
			return $this->movie;
		}

		public function getRentalMoney(){
			$money = 0;
			switch ($this->movie->getType()) {
				case Movie::$NEW:
					$money+=1.5;
					break;
				case Movie::$CHILDREN:
					$money+=0.8;
					break;
				case Movie::$POPULAR:
					$money+=1.8;
					break;
				default:
					$money+=1;
					break;
			}
			$money *= $this->getDaysRentaled();
			return $money;
		}

		public function getRentalFreque(){
			$freque = 1;
			if($this->getDaysRentaled()>2){
				$freque = $this->getDaysRentaled()*1.2;
			}
			return $freque;
		}
	}

	class Movie{

		public static $NEW = 0;
		public static $POPULAR = 1;
		public static $CHILDREN = 2;
		public static $NORMAL = 4;

		private $title;
		private $type;

		public function __construct($title,$type=4){
			$this->title = $title;
			$this->type = $type;
		}

		public function getTitle(){
			return $this->title;
		}

		public function getType(){
			return $this->type;
		}

	}

	$movie1 = new Movie("Gone with the Wind");
	$movie2 = new Movie("Tidy");
	$movie3 = new Movie("Sword Art Online",Movie::$CHILDREN);
	$movie4 = new Movie("Cross The Start",Movie::$NEW);

	$retal1 = new Rental($movie1,2);
	$retal2 = new Rental($movie2,1);
	$retal3 = new Rental($movie3,3);
	$retal4 = new Rental($movie4,5);

	$customer = new Customer("Violin");
	$customer->addRental($retal1);
	$customer->addRental($retal2);
	$customer->addRental($retal3);
	$customer->addRental($retal4);

	echo $customer->statement();
?>